package com.ywl.designpattern.state;

// 售出状态
public class SoldState implements State {
    VendingMachine vendingMachine;

    public SoldState(VendingMachine vendingMachine) {
        this.vendingMachine = vendingMachine;
    }

    @Override
    public void insertCoin() {
        System.out.println("请等待，我们正在给您商品");
    }

    @Override
    public void ejectCoin() {
        System.out.println("抱歉，您已经选择了商品");
    }

    @Override
    public void selectItem() {
        System.out.println("您已经选择了商品");
    }

    @Override
    public void dispense() {
        vendingMachine.releaseBall();
        if (vendingMachine.getCount() > 0) {
            vendingMachine.setState(vendingMachine.getNoCoinState());
        } else {
            System.out.println("糟糕，商品售罄");
            vendingMachine.setState(vendingMachine.getSoldOutState());
        }
    }
}
